package com.bwie.coupon.service.impl;

import com.bwie.common.core.domain.PageResult;
import com.bwie.coupon.domain.dto.CouponPlatformDTO;
import com.bwie.coupon.domain.po.CouponPO;
import com.bwie.coupon.domain.vo.CouponPlatformVO;
import com.bwie.coupon.mapper.CouponPlatformMapper;
import com.bwie.coupon.service.ICouponPlatformService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CouponPlatformServiceImpl implements ICouponPlatformService {
    @Autowired
    private CouponPlatformMapper couponPlatformMapper;

    /**
     * 平台端
     * 获取待审核优惠券列表
     * @param couponPlatformDTO
     * @return
     */
    @Override
    public PageResult<CouponPlatformVO> selectCouponPlatformList(CouponPlatformDTO couponPlatformDTO) {
        //调用分页工具
        PageHelper.startPage(couponPlatformDTO.getPageNum(),couponPlatformDTO.getPageSize());
        List<CouponPlatformVO> list = couponPlatformMapper.selectCouponPlatformList(couponPlatformDTO);
        PageInfo<CouponPlatformVO> pageInfo = new PageInfo<>(list);
        return PageResult.toPageResult(pageInfo.getTotal(),list);
    }

    /**
     * 平台端
     * 根据优惠券id查看未审核优惠券详情
     * @param couponId
     * @return
     */
    @Override
    public CouponPlatformVO getCouponDetails(Long couponId) {
        return couponPlatformMapper.selectCouponDetailById(couponId);
    }

    /**
     * 平台端
     * 根据优惠券id修改审核状态
     * @param couponId
     * @param
     */
    @Override
    public void couponAudit(Long couponId,Integer reviewStatus) {
        //根据id查询一条优惠券信息
        CouponPO couponPO = couponPlatformMapper.selectOneById(couponId);

        //只能审核正在进行中的优惠券
        if (couponPO.getState() == 0){
            couponPlatformMapper.couponAudit(couponId,reviewStatus);
        }
    }
}
